package util;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class CurrencyUtil {

	// 雅虎汇率查询
	// public static String lookup(String curNo) {
	// String url =
	// "http://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=" +
	// curNo + "CNY=x";
	// String result = new String(HttpUtil.call(url));
	// String[] res = result.split(",");
	// String r = res[1].replaceAll("\"", "");
	// return r;
	// }

	// 极速汇率查询
	public static String lookup(String curNo) throws Exception {
		String url = "http://op.juhe.cn/onebox/exchange/currency?key=1c5ab4d0d383f1f18bd1e40ade5d7852&from=" + curNo + "&to=CNY";
		String res = new HttpUtil().get(url, null);
		JSONObject json = JSONObject.fromObject(res);
		JSONArray resultarr = json.optJSONArray("result");
		JSONObject resultobj=resultarr.getJSONObject(0);
		String rate = resultobj.getString("result");
		return rate;
	}

	public static void main(String[] args) throws Exception {
		System.out.println(lookup("MXN"));
	
	}
}
